import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:vape_xe/services/services.dart';
import 'package:vape_xe/utils/utils.dart';
import 'package:vape_xe/values/values.dart';
import 'package:vape_xe/widgets/widgets.dart';

import 'logic.dart';

class ScanDialogView extends Dialog {
  final Map<String, dynamic> params;

  const ScanDialogView({super.key, required this.params});

  @override
  Widget build(BuildContext context) {
    return GetX<ScanDialogController>(
      init: Get.put(ScanDialogController(params)),
      builder: (controller) => Scaffold(
        backgroundColor: Colors.transparent,
        body: Center(
          child: Container(
            margin: EdgeInsets.symmetric(horizontal: 48.w),
            decoration: BoxDecoration(
              color: Colors.black,
              borderRadius: 20.radius,
              boxShadow: [Shadows.dialogShadow],
            ),
            child: SingleChildScrollView(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Stack(
                    children: [
                      Align(
                        alignment: Alignment.center,
                        child: Padding(
                          padding: EdgeInsets.only(top: 27.h),
                          child: netImageCached(
                            controller.params['icon'],
                            width: 153.w,
                            height: 187.w,
                            showProgress: false,
                            showError: false,
                          ),
                        ),
                      ),
                      Align(
                        alignment: Alignment.topRight,
                        child: Padding(
                          padding: EdgeInsets.only(top: 12.h, right: 12.h),
                          child: InkWell(
                              onTap: () => Navigator.pop(context),
                              child: Image.asset('assets/images/ic_close.webp', width: 32.w, height: 35.w)),
                        ),
                      )
                    ],
                  ),
                  24.hGap,
                  Text(
                    'LV.${controller.params['level']}',
                    style: TextStyle(
                      color: AppColors.levelHaloColor[controller.params['level']],
                      fontFamily: 'Montserrat',
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  12.hGap,
                  Text(
                    controller.params['name'],
                    style: TextStyle(fontFamily: 'Montserrat', fontWeight: FontWeight.bold, fontSize: 20.sp),
                  ),
                  4.hGap,
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Image.asset(
                        'assets/images/ic_paopao.webp',
                        width: 14.w,
                        height: 14.w,
                      ),
                      4.vGap,
                      Text(
                        '+${controller.params['coin']}',
                        style: TextStyle(
                          fontSize: 16.sp,
                          fontWeight: FontWeight.bold,
                          fontFamily: 'Montserrat',
                          color: Colors.white,
                        ),
                      )
                    ],
                  ),
                  4.hGap,
                  Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                    Text(
                      'Profit per hour'.tr,
                      style: TextStyle(fontSize: 11.sp, color: Colors.white30),
                    ),
                    if (controller.params['hours'] != null)
                      Text(
                        controller.params['hours'] > 24
                            ? '（${controller.params['hours'] / 24}*24 hours）'
                            : '（${controller.params['hours']} hours）',
                        style: TextStyle(fontSize: 11.sp, color: Colors.white30),
                      ),
                  ]),
                  24.hGap,
                  Text(
                    'Congratulations! You got a rewards:'.tr,
                    style: const TextStyle(color: Colors.white30),
                  ),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Padding(
                        padding: EdgeInsets.only(bottom: 3.h),
                        child: Text(
                          ConfigStore.to.currency,
                          style: TextStyle(
                            fontSize: 11.sp,
                            fontFamily: 'Montserrat',
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                      Text(
                        controller.params['rewardsMyself'].toString().removeZero(),
                        style: TextStyle(
                          fontSize: 16.sp,
                          fontFamily: 'Montserrat',
                          fontWeight: FontWeight.bold,
                        ),
                      )
                    ],
                  ),
                  28.hGap,
                  VerificationCode(
                    fullBorder: true,
                    widthSize: 40.w,
                    heightSize: 44.h,
                    gapSize: 12.w,
                    textStyle: TextStyle(fontSize: 20.sp, fontFamily: 'Montserrat', fontWeight: FontWeight.bold),
                    keyboardType: TextInputType.number,
                    underlineColor: Colors.white10,
                    underlineUnfocusedColor: Colors.transparent,
                    fillColor: Colors.white10,
                    length: 6,
                    onCompleted: (String value) {
                      controller.inviteCode.value = value;
                      FocusScope.of(context).unfocus();
                    },
                    onEditing: (bool value) {
                      controller.inviteCode.value = '';
                    },
                  ),
                  12.hGap,
                  Text(
                    'Input invite code to get extra bonus:'.tr,
                    style: TextStyle(
                      foreground: Paint()
                        ..shader = const LinearGradient(
                          colors: <Color>[Color(0xffF5B946), Color(0xffF58546)],
                        ).createShader(
                          const Rect.fromLTWH(0.0, 0.0, 300.0, 0.0),
                        ),
                    ),
                  ),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Padding(
                        padding: EdgeInsets.only(bottom: 3.h),
                        child: Text(
                          ConfigStore.to.currency,
                          style: TextStyle(
                            fontSize: 11.sp,
                            fontFamily: 'Montserrat',
                            fontWeight: FontWeight.bold,
                            color: const Color(0xffF58546),
                          ),
                        ),
                      ),
                      Text(
                        controller.params['rewardsInviteMyself'].toString().removeZero(),
                        style: TextStyle(
                          fontSize: 16.sp,
                          fontFamily: 'Montserrat',
                          fontWeight: FontWeight.bold,
                          color: const Color(0xffF58546),
                        ),
                      )
                    ],
                  ),
                  16.hGap,
                  Divider(
                    height: 0.5.h,
                    color: Colors.white10,
                  ),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Expanded(
                        child: TextButton(
                          onPressed: () => controller.noExtra(),
                          child: Text(
                            'OK'.tr,
                            style:
                                TextStyle(fontWeight: FontWeight.bold, fontSize: 16.sp, color: AppColors.primaryText),
                          ),
                        ),
                      ),
                      Expanded(
                        child: TextButton(
                          onPressed: () => controller.getExtra(),
                          child: Text(
                            'Get extra'.tr,
                            style: TextStyle(
                              fontWeight: FontWeight.bold,
                              fontSize: 16.sp,
                              color: controller.inviteCode.value.isEmpty ? AppColors.thirdText : AppColors.primaryText,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
